package com.longge;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class FindRepeatedDnaSequences {


    public List<String> findRepeatedDnaSequences(String s) {

        char[] chars = s.toCharArray();
        int i = 0;
        HashSet<String> set = new HashSet<>();
        HashSet<String> ans = new HashSet<>();
        while (chars.length - i >= 10) {
            char[] dest = new char[10];
            System.arraycopy(chars, i, dest, 0, 10);
            if (!set.add(new String(dest))) {
                ans.add(new String(dest));
            }
            i++;
        }
        return new ArrayList<>(ans);
    }


}
